package com.miyake.loveviewweb.client.viewer.table;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.miyake.loveviewweb.client.DataServiceWrapper;
import com.miyake.loveviewweb.shared.model.DataModel;

public class ContentGetter {
    public interface DataModelHandler {
        void onUpdate(DataModel dataModel);
    }
    
    public ContentGetter(DataModel dataModel, final DataModelHandler handler) {
        if (!dataModel.isContent()){
            DataServiceWrapper.getInstance().getService().getData(dataModel.getKey(), true, new AsyncCallback<DataModel>() {
                public void onFailure(Throwable caught) { 
                    Window.alert(caught.getMessage());
                }

                public void onSuccess(DataModel result) {
                    handler.onUpdate(result);
                }   
            });
        }
        else {
            handler.onUpdate(dataModel);
        }
    }
}
